/*
  Copyright (C) 2011, Kyungjoo Kim
  
  This file is part of UHM (Unassembled HyperMatrix) sparse direct solver.
  
  All rights reserved.

  This library is free software; you can redistribute it and/or
  modify it under the terms of the GNU Lesser General Public
  License as published by the Free Software Foundation; either
  version 2.1 of the License, or (at your option) any later version.
  
  This library is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  Lesser General Public License for more details.
  
  You should have received a copy of the GNU Lesser General Public
  License along with this library; if not, write to the Free Software
  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
  Also add information on how to contact you by electronic and paper mail.
  
  
  Kyungjoo Kim
  iamkyungjoo@gmail.com
*/
#ifndef UHM_WRAPPER_FORT_COMMON_HXX_
#define UHM_WRAPPER_FORT_COMMON_HXX_

enum { UHM_FORT_BEGIN = 1,
       UHM_FORT_CHOL_NOPIV=1,
       UHM_FORT_CHOL_PIV,
       UHM_FORT_CHOL_INCPIV,
       UHM_FORT_LDL_NOPIV=11,
       UHM_FORT_LDL_PIV,
       UHM_FORT_LDL_INCPIV,
       UHM_FORT_LU_NOPIV=21,
       UHM_FORT_LU_PIV,
       UHM_FORT_LU_INCPIV,
       UHM_FORT_END,
       UHM_FORT_PETSC_BEGIN = 101,
       UHM_FORT_PETSC_CHOL_NOPIV=101,
       UHM_FORT_PETSC_CHOL_PIV,
       UHM_FORT_PETSC_CHOL_INCPIV,
       UHM_FORT_PETSC_LDL_NOPIV=111,
       UHM_FORT_PETSC_LDL_PIV,
       UHM_FORT_PETSC_LDL_INCPIV,
       UHM_FORT_PETSC_LU_NOPIV=121,
       UHM_FORT_PETSC_LU_PIV,
       UHM_FORT_PETSC_LU_INCPIV,
       UHM_FORT_PETSC_END,};

#define UHM_FORT_SOLVER_LINAL_PTR(S,N,E,In)                             \
  {                                                                     \
    switch (In->second) {                                               \
    case UHM_FORT_PETSC_CHOL_NOPIV:                                     \
    case UHM_FORT_CHOL_NOPIV:        S = (Direct_Solver_<N,E,CHOL_nopiv_Linal_>*)(In->first); break; \
    case UHM_FORT_PETSC_CHOL_PIV:                                       \
    case UHM_FORT_CHOL_PIV:          S = (Direct_Solver_<N,E,CHOL_piv_Linal_>*)(In->first); break; \
    case UHM_FORT_PETSC_CHOL_INCPIV:                                    \
    case UHM_FORT_CHOL_INCPIV:       S = (Direct_Solver_<N,E,CHOL_incpiv_Linal_>*)(In->first); break; \
    case UHM_FORT_PETSC_LDL_NOPIV:                                      \
    case UHM_FORT_LDL_NOPIV:         S = (Direct_Solver_<N,E,LDL_nopiv_Linal_>*)(In->first); break; \
    case UHM_FORT_PETSC_LDL_PIV:                                        \
    case UHM_FORT_LDL_PIV:           S = (Direct_Solver_<N,E,LDL_piv_Linal_>*)(In->first); break; \
    case UHM_FORT_PETSC_LDL_INCPIV:                                     \
    case UHM_FORT_LDL_INCPIV:        S = (Direct_Solver_<N,E,LDL_incpiv_Linal_>*)(In->first); break; \
    case UHM_FORT_PETSC_LU_NOPIV:                                       \
    case UHM_FORT_LU_NOPIV:          S = (Direct_Solver_<N,E,LU_nopiv_Linal_>*)(In->first); break; \
    case UHM_FORT_PETSC_LU_PIV:                                         \
    case UHM_FORT_LU_PIV:            S = (Direct_Solver_<N,E,LU_piv_Linal_>*)(In->first); break; \
    case UHM_FORT_PETSC_LU_INCPIV:                                      \
    case UHM_FORT_LU_INCPIV:         S = (Direct_Solver_<N,E,LU_incpiv_Linal_>*)(In->first); break; \
    default:                                                            \
      UHM_ERROR(false, ">> Wrong Method");                              \
    }                                                                   \
  }

#define UHM_FORT_SOLVER_LINAL_PETSC_PTR(S,N,E,In)                       \
  {                                                                     \
    switch (In->second) {                                               \
    case UHM_FORT_PETSC_CHOL_NOPIV:  S = (PETSC_Solver_<N,E,CHOL_nopiv_Linal_>*)(In->first); break; \
    case UHM_FORT_PETSC_CHOL_PIV:    S = (PETSC_Solver_<N,E,CHOL_piv_Linal_>*)(In->first); break; \
    case UHM_FORT_PETSC_CHOL_INCPIV: S = (PETSC_Solver_<N,E,CHOL_incpiv_Linal_>*)(In->first); break; \
    case UHM_FORT_PETSC_LDL_NOPIV:   S = (PETSC_Solver_<N,E,LDL_nopiv_Linal_>*)(In->first); break; \
    case UHM_FORT_PETSC_LDL_PIV:     S = (PETSC_Solver_<N,E,LDL_piv_Linal_>*)(In->first); break; \
    case UHM_FORT_PETSC_LDL_INCPIV:  S = (PETSC_Solver_<N,E,LDL_incpiv_Linal_>*)(In->first); break; \
    case UHM_FORT_PETSC_LU_NOPIV:    S = (PETSC_Solver_<N,E,LU_nopiv_Linal_>*)(In->first); break; \
    case UHM_FORT_PETSC_LU_PIV:      S = (PETSC_Solver_<N,E,LU_piv_Linal_>*)(In->first); break; \
    case UHM_FORT_PETSC_LU_INCPIV:   S = (PETSC_Solver_<N,E,LU_incpiv_Linal_>*)(In->first); break; \
    default:                                                            \
      UHM_ERROR(false, ">> Wrong Method");                              \
    }                                                                   \
  }


#endif
